package dao

import javax.inject.{Inject, Singleton}
import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import scala.concurrent.ExecutionContext.Implicits.global

/**
 * Created by yz on 2018/5/29
 */
@Singleton
class GtexSupplementIndexDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends
  HasDatabaseConfigProvider[JdbcProfile] {

  import profile.api._

  def deleteAll = db.run(GtexSupplementIndex.delete).map(_ => ())

  def insertAll(rows: List[GtexSupplementIndexRow]) = db.run(GtexSupplementIndex ++= rows).map(_ => ())

  def selectOp(location: String) = db.run(GtexSupplementIndex.filter(_.location === location).map(_.index).
    result.headOption)

  def select(location: String) = db.run(GtexSupplementIndex.filter(_.location === location).map(_.index).
    result.head)

}
